<template>
	<el-dialog :visible.sync="dialogVisible" title="发货信息" width="800px" v-drag2anywhere :close-on-click-modal="false">
		<el-form :model="formData" ref="form" label-width="90px" >
			<el-row>
        <el-col :span="8">
        	<el-form-item label="下单日期:">{{formData.orderdate}}</el-form-item>
        </el-col>
        <el-col :span="10">
        	<el-form-item label="外部订单号:">{{formData.ordercode}}</el-form-item>
        </el-col>
        <el-col :span="6">
        	<el-form-item label="渠道名称:">{{formData.platform}}</el-form-item>
        </el-col>
        <el-col >
        	<el-form-item label="商品明细:">
             <el-table :data="goods" border>
               <el-table-column label="产品名称" prop="title"></el-table-column>
                <el-table-column label="品牌" prop="brand"  width="100px"></el-table-column>
                <el-table-column label="规格型号" prop="model"></el-table-column>
                <el-table-column label="单位" prop="unit" width="100px"></el-table-column>
                <el-table-column label="数量" prop="count"  width="100px"></el-table-column>
             </el-table>
          </el-form-item>
        </el-col>
			</el-row>
			<el-row>
				<el-col :span="8">
					<el-form-item label="物流名称:" prop="name">
            <el-input v-model="formData.deliver.name" placeholder="快递或物流名称"></el-input>
          </el-form-item>
				</el-col>
        <el-col :span="16">
        	<el-form-item label="物流单号:" prop="num">
            <el-input v-model="formData.deliver.num" placeholder="物流单号"></el-input>
          </el-form-item>
        </el-col>
        <el-col >
        	<el-form-item label="物流备注:">
            <el-input type="textarea" v-model="formData.deliver.memo" placeholder="物流备注信息" :rows="3"></el-input>
          </el-form-item>
        </el-col>
			</el-row>
		</el-form>
		<div slot="footer" class="dialog-footer">
      <el-button type="success" size="medium" v-if="formData.bind_buycodes.trim()!=''" @click="handleAsyncDeliver">同步成本发货状态</el-button>
			<el-button type="primary" size="medium" @click="handleSave">确定</el-button>
		</div>
	</el-dialog>
</template>

<script>
	export default {
		data() {
			return {
				index: -1,
				formData: {
					orderdate: '',
					ordercode: '',
					type: 1,
					deliver:{
            name:'',
            num:'',
            memo:'',
            status:0
          },
          deliverstatus:0,
				},
 				dialogVisible: false,
				postlist: [],
        goods:[],
			}
		},
		methods: {
			init(index, data) {
				this.index = index;
				this.formData = data;
        this.goods=[];
        this.deliverstatus=this.formData.deliverstatus;
        this.goods.push({
          title:this.formData.title,
          model:this.formData.model,
          brand:this.formData.brand,
          unit:this.formData.unit,
          count:this.formData.count,
        })

			},
      handleSave(){
        const params={
          id:this.formData.did,
          name:this.formData.deliver.name,
          num:this.formData.deliver.num,
          status:parseInt(this.formData.deliverstatus),
          memo:this.formData.deliver.memo
        }
         this.axios.post("api/admin/orderdetail/updatedeliver",params).then(res=>{
            if(res.status==200 && res.data.code){
              this.$message.success({
                message: res.data.msg,
                duration: 1500,
                showClose: true
              });
              this.dialogVisible=false;
              this.$emit("updated",this.index,params);
            }else{
              this.$message.error({
                message: res.data.msg,
                duration: 1500,
                showClose: true
              });
            }
         })
      },
      handleAsyncDeliver(){
        this.$confirm("确定要获取关联成本发货状态吗?","提示").then(res=>{
           const params={
              buycode:this.formData.bind_buycodes
           }
          this.axios.post("api/admin/buylist/getdeliver",params).then(res=>{
             if(res.status==200 && res.data.code){
               this.$message.success({
                 message: res.data.msg,
                 duration: 1500,
                 showClose: true
               });
               this.formData.deliver.name=res.data.deliver.name;
               this.formData.deliver.num=res.data.deliver.num;
               this.formData.deliver.memo=res.data.deliver.memo;
             }else{
               this.$message.error({
                 message: res.data.msg,
                 duration: 1500,
                 showClose: true
               });
             }
          })
        })
      }
		}
	}
</script>

<style>
</style>
